instance-ssh-key-dir:
  file.directory:
    - name: /root/.ssh
    - user: root
    - group: root
    - mode: 700

instance-ssh-private-key:
  file.managed:
    - name: /root/.ssh/id_rsa
    - source: salt://openstack/queen/instance/files/id_rsa
    - user: root
    - group: root
    - mode: 600
    - require:
      - file: instance-ssh-key-dir

instance-ssh-public-key:
  file.managed:
    - name: /root/.ssh/id_rsa.pub
    - source: salt://openstack/queen/instance/files/id_rsa.pub
    - user: root
    - group: root
    - mode: 644
    - require:
      - file: instance-ssh-private-key

instance-demo-create:
  file.managed:
    - name: /etc/script/instance-demo-create.sh
    - source: salt://openstack/queen/instance/files/instance-demo-create.sh
    - user: root
    - group: root
    - mode: 700
    - template: jinja
    - defaults:
      INSTANCE_SUBNET_START: {{ pillar['instance']['INSTANCE_SUBNET_START'] }}
      INSTANCE_SUBNET_END: {{ pillar['instance']['INSTANCE_SUBNET_END'] }}
      INSTANCE_DNS: {{ pillar['instance']['INSTANCE_DNS'] }}
      INSTANCE_GATEWAY: {{ pillar['instance']['INSTANCE_GATEWAY'] }}
      INSTANCE_SUBNET_RANGE: {{ pillar['instance']['INSTANCE_SUBNET_RANGE'] }}
  cmd.run:
    - name: bash /etc/script/instance-demo-create.sh && touch /etc/lock/instance-demo-create.lock
    - require:
      - file: instance-ssh-public-key
    - unless : test -f /etc/lock/instance-demo-create.lock
